package com.rxjava.simpleio3;

import com.rxjava.User;
import com.rxjava.myrxjava.os.Handler;

/**
 * Created by iceGeneral on 2016/10/15.
 */
public class Test {
    public static void main(String[] args) {
        Handler handler = new Handler();
        Observable.create(new OnSubscribe<Integer>() {
            @Override
            public void call(Subscriber<? super Integer> subscriber) {
                System.out.println("create() " + Thread.currentThread());
                subscriber.onNext(10);
            }
        })
        .map(new Func1<Integer, String>() {
        	@Override
        	public String call(Integer integer) {
        		System.out.println("map() " + Thread.currentThread());
        		return "map" + integer;
        	}
        })
        .observeOn(handler)
        .map(new Func1<String, User>() {
            @Override
            public User call(String name) {
                System.out.println("map2() " + Thread.currentThread());
                return new User(name);
            }
        })
        .subscribeOnIO()
        .subscribe(new Subscriber<User>() {
            @Override
            public void onNext(User u) {
                System.out.println("onNext() " + Thread.currentThread());
                System.out.println(u);
            }
        });
        System.out.println("-------------------------------------------------------------");
        handler.loop();

    }

}
